import request from '@/utils/request'
const api = {
    userList: '/user/list',
    delete: '/user/delete',
    add: '/user/add',
    edit: '/user/update'
}

const Map = {
  '在线': '1',
  '离线': '0',
  'ascend': 'asc',
  'descend': 'desc'
}
export function getUserList (parameter) {
    return request({
      url: api.userList,
      method: 'get',
      params: {
        page: parameter.page || 1,
        pageSize: parameter.pageSize || 10,
        name: parameter.name,
        role: parameter.role,
        status: Map[parameter.status],
        order: Map[parameter.order] || 'asc'
      }
    })
}
export function deleteUser (id) {
  return request({
    url: api.delete,
    method: 'delete',
    params: {
      id: id
    }
  })
}
export function addUser (userInfo) {
  return request({
    url: api.add,
    method: 'post',
    data: {
      username: userInfo.username,
      password: userInfo.password,
      role: userInfo.role
    }
  })
}
export function editUser (userInfo) {
  return request({
    url: api.edit,
    method: 'put',
    data: {
      id: userInfo.id,
      username: userInfo.username,
      password: userInfo.password,
      role: userInfo.role,
      age: userInfo.age,
      email: userInfo.email,
      sex: userInfo.sex,
      avatar: userInfo.avatar
    }
  })
}
export function roleList () {
  return request({
    url: 'role/roleName',
    method: 'get'
  })
}
